// 定义记分牌的类ScorePanel
class ScorePanel {
    // 直接赋值，类型推断会检测出number类型，可以不用写类型
    score = 0;
    level = 1;
    scoreEle: HTMLElement;
    levelEle: HTMLElement;
    maxLevel: number;//限制等级
    upScore: number;//表示多少分升级
    constructor(maxLevel: number = 10, upScore: number = 10) {
        this.levelEle = document.getElementById('level')!;
        this.scoreEle = document.getElementById('score')!;
        this.maxLevel = maxLevel;
        this.upScore = upScore;
    }
    // 设置一个加分的方法
    addScore() {
        this.scoreEle.innerHTML = ++this.score + '';
        // 判断当前分数是否应该升一级
        if (this.score % this.upScore === 0) {
            this.levelUp();
        }
    }
    // 提升等级的方法
    levelUp() {
        if (this.level < this.maxLevel) {
            this.levelEle.innerHTML = ++this.level + '';
        }
    }
}
// 测试
/* const scorePanel = new ScorePanel();
scorePanel.addScore()
scorePanel.levelUp() */


export default ScorePanel;